package Thread.singleton_pattern;

/**
 * 懒汉式单例模式
 * 第一次调用才实例化对象
 */
public class Singletest2 {
    private static volatile Singletest2 singletest2;
    private Singletest2(){
        int x=10;
        int y=20;
        int z=30;
    };

    public  static Singletest2 getSingle() {
        if (singletest2==null) {
            synchronized (Singletest2.class) {
                if (singletest2==null) {
                    singletest2 = new Singletest2();
                }
            }
        }
        return singletest2;
    }
}

class Singletest2Main{
    public static void main(String[] args) {
      Singletest2 s1=Singletest2.getSingle();
      Singletest2 s2=Singletest2.getSingle();
      Singletest2 s3=Singletest2.getSingle();
        System.out.println(s1==s2);
        System.out.println(s1==s3);
    }
}
